package org.example.mapper;

import org.apache.ibatis.annotations.*;
import org.example.pojo.Emp;

import java.time.LocalDate;
import java.util.List;

@Mapper
public interface EmpMapper {

    // 删除员工
    @Delete("delete from tb_emp where id = #{id}")
    void deleteEmpById(Integer id);

    // 新增员工
    @Options(useGeneratedKeys = true, keyProperty = "id")
    void insertEmp(Emp emp);

    // 修改员工
    void updateEmp(Emp emp);

    // 根据 id 进行查询
//    @Results({
//            @Result(column = "dept_id", property = "deptId"),
//            @Result(column = "entrydate", property = "entryDate"),
//            @Result(column = "create_time", property = "createTime"),
//            @Result(column = "update_time", property = "updateTime")
//    })
//    @Select("select * from tb_emp where id = #{id}")
//    Emp getEmpById(Integer id);
    // 开启驼峰命名的自动映射开关 （推荐）
    @Select("select * from tb_emp where id = #{id}")
    Emp getEmpById(Integer id);

    // 条件查询 姓名 性别 入职时间（范围）这三个参数
//    @Select("select * from tb_emp where name like '%${name}%' and gender = #{gender} and entrydate between #{beginTime} and #{endTime} order by update_time desc ")
//    @Select("select * from tb_emp where name like concat('%', #{name}, '%') and gender = #{gender} and entrydate between #{beginTime} and #{endTime} order by update_time desc ")

    List<Emp> getEmpByList(String name, Short gender, LocalDate beginTime, LocalDate endTime);


    // 条件查询 姓名 性别 入职时间（范围）这三个参数 动态 sql (if)
    List<Emp> getEmpByListDynamicSql(String name, Short gender, LocalDate beginTime, LocalDate endTime);

    // 批量通过 id 进行批量删除
    void deleteEmpByIds(List<Integer> ids);

    @Select("select count(*) from tb_emp")
    Long total();



    // 条件查询全部用户信息（分页)
    List<Emp> list(String keyword, Integer gender, LocalDate beginTime, LocalDate endTime);

    @Select("select * from tb_emp where username = #{username} and password = #{password}")
    Emp getUserByUserNameAndPassword(Emp emp);
}
